
import { loadEnv } from 'vite'

interface VITE_ENV_CONFIG {
  VITE_API_HOST: string
  VITE_PACK_ENV: string
  VITE_PACK_URL: string
}

const envScript = (process.env as any).npm_lifecycle_script.split(' ')
const envName = envScript[envScript.length - 1] // 通过启动命令区分环境
const envData = loadEnv(envName, 'env') as unknown as VITE_ENV_CONFIG
export default defineNuxtConfig({
    runtimeConfig: {
        public: envData // 把env放入这个里面，通过useRuntimeConfig获取
      },
    app: {
        head: {
            title: 'nuxt',
            htmlAttrs: {
                lang: 'en',
            },
            meta: [
                { charset: 'utf-8' },
                { name: 'viewport', content: 'width=device-width, initial-scale=1' },
                { hid: 'description', name: 'description', content: '' },
                { name: 'format-detection', content: 'telephone=no' },
            ],
            link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
        },
        
    },
    css: [
        'ant-design-vue/dist/antd.css'
    ],
    vite: {
        envDir: '~/env',
        css: {
            preprocessorOptions: {
                less: {
                    additionalData: '@use "@/assets/styles/global.scss" as *;'	// 注意文件路径要配成自己的
                }
            }
        }
    },
    nitro: {
        devProxy: {
            '/api/': 'http://182.92.219.214:8123'
            // '/api': {
            //     target: 'http://182.92.219.214:8123',
            //     prependPath: true,
            //     changeOrigin: true,
            //     rewrite: (url: string) => url.replace(/^\/api/, ""),
            // },
        }
    },
})
